//
//  XQAuthenticationCell.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/22.
//

#import "XQAuthenticationCell.h"

@interface XQAuthenticationCell()
@property (nonatomic,strong) UIView *bgView;
@property (nonatomic,strong) UILabel *numberLb;
@property (nonatomic,strong) UILabel *contentLb;
@property (nonatomic,strong) UIImageView *arrowImageView;
@end

@implementation XQAuthenticationCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = kCardColor;
        [self makeUI];
        [self makeConstraints];
    }
    return self;
}

- (void)makeUI {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.numberLb];
    [self.bgView addSubview:self.contentLb];
    [self.bgView addSubview:self.arrowImageView];
}

- (void)makeConstraints {
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.height.mas_equalTo(44);
        make.bottom.equalTo(@-10);
    }];
    [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        (void)make.centerY;
        make.left.equalTo(@50);
        make.right.equalTo(@-100);
    }];
    [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.equalTo(@0);
        make.width.mas_equalTo(91);
    }];
}

#pragma mark - setter

- (void)setIndex:(NSInteger)index {
    self.numberLb.text = [NSString stringWithFormat:@"0%ld",index];
}

//- (void)setContent:(NSString *)content {
//    self.contentLb.text = content;
//}
//
//- (void)setImageName:(NSString *)imageName {
//    self.arrowImageView.image = [UIImage imageNamed:imageName];
//}

- (void)setModel:(XQAuthendicationListModel *)model {
    self.contentLb.text = model.won;
    NSString *imageName = [model.evasive integerValue] == 1 ? @"certification" : @"certification_un";
    self.arrowImageView.image = [UIImage imageNamed:imageName];
}

#pragma mark - lazy

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 15;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UILabel *)numberLb {
    if (!_numberLb) {
        _numberLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 13, 30, 18)];
        _numberLb.backgroundColor = [UIColor blueColor];
        _numberLb.textColor = [UIColor whiteColor];
        _numberLb.font = [UIFont boldSystemFontOfSize:16];
        
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:_numberLb.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(9, 9)];
        CAShapeLayer *mask = [CAShapeLayer layer];
        mask.path = path.CGPath;
        _numberLb.layer.mask = mask;
    }
    return _numberLb;
}

- (UILabel *)contentLb {
    if (!_contentLb) {
        _contentLb = [[UILabel alloc] init];
        _contentLb.textColor = kBlackTextColor;
        _contentLb.font = [UIFont boldSystemFontOfSize:16];
        _contentLb.adjustsFontSizeToFitWidth = YES;
    }
    return _contentLb;
}

- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [[UIImageView alloc] init];
        [_arrowImageView setUserInteractionEnabled:YES];
    }
    return _arrowImageView;
}


@end
